home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume18 / undel / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-05-06  |  21.3 KB

  1. Path: uunet!bbn.com!rsalz
  2. From: rsalz@uunet.uu.net (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v18i074:  MIT Athena delete/undelete programs, Part02/06
  5. Message-ID: <1634@fig.bbn.com>
  6. Date: 29 Mar 89 04:31:26 GMT
  7. Lines: 815
  8. Approved: rsalz@uunet.UU.NET
  9.  
  10. Submitted-by: Jonathan I. Kamens <jik@PIT-MANAGER.MIT.EDU>
  11. Posting-number: Volume 18, Issue 74
  12. Archive-name: undel/part02
  13.  
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 2 (of 6)."
  22. # Contents:  Makefile col.c man1/delete.1 util.c
  23. # Wrapped by jik@pit-manager on Mon Mar 27 12:16:48 1989
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'Makefile'\"
  27. else
  28. echo shar: Extracting \"'Makefile'\" \(4426 characters\)
  29. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  30. X#     Copyright 1988 Massachusetts Institute of Technology.
  31. X#
  32. X#     For copying and distribution information, see the file
  33. X#     "mit-copyright.h".
  34. X#
  35. X#     $Source: /mit/jik/src/delete/RCS/Makefile,v $
  36. X#     $Author: jik $
  37. X#     $Header: Makefile,v 1.8 89/03/27 12:03:33 jik Exp $
  38. X#
  39. X
  40. XDESTDIR =
  41. XTARGETS = delete undelete expunge purge lsdel
  42. XINSTALLDIR = /bin/athena
  43. XCC = cc
  44. XCFLAGS = -O
  45. XSRCS = delete.c undelete.c directories.c pattern.c util.c expunge.c \
  46. X    lsdel.c col.c
  47. X
  48. Xall: $(TARGETS)
  49. X
  50. Xinstall:
  51. X    for i in $(TARGETS) ;\
  52. X    do \
  53. X    install -c -s $$i $(DESTDIR)$(INSTALLDIR) ; \
  54. X    install -c man1/$$i.1 $(DESTDIR)/usr/man/man1 ; \
  55. X    done
  56. X
  57. Xdelete: delete.o util.o
  58. X    cc $(CFLAGS) -o delete delete.o util.o
  59. X
  60. Xsaber_delete:
  61. X    #alias s step
  62. X    #alias n next
  63. X    #load delete.c util.c
  64. X
  65. Xundelete: undelete.o directories.o util.o pattern.o
  66. X    cc $(CFLAGS) -o undelete undelete.o directories.o util.o pattern.o
  67. X
  68. Xsaber_undelete:
  69. X    #alias s step
  70. X    #alias n next
  71. X    #load undelete.c directories.c util.c pattern.c
  72. X
  73. Xexpunge: expunge.o directories.o pattern.o util.o col.o
  74. X    cc $(CFLAGS) -o expunge expunge.o directories.o pattern.o \
  75. X        util.o col.o
  76. X
  77. X
  78. Xsaber_expunge:
  79. X    #alias s step
  80. X    #alias n next
  81. X    #load expunge.c directories.c pattern.c util.c col.c
  82. X
  83. Xpurge: expunge
  84. X    ln -s expunge purge
  85. X
  86. Xlsdel: lsdel.o util.o directories.o pattern.o col.o
  87. X    cc $(CFLAGS) -o lsdel lsdel.o util.o directories.o pattern.o col.o
  88. X
  89. Xsaber_lsdel:
  90. X    #alias s step
  91. X    #alias n next
  92. X    #load lsdel.c util.c directories.c pattern.c col.c
  93. X
  94. Xclean:
  95. X    -rm -f *~ *.bak *.o delete undelete lsdel expunge purge
  96. X
  97. Xdepend: delete.c undelete.c
  98. X    /usr/athena/makedepend -v $(CFLAGS) -s'# DO NOT DELETE' $(SRCS)
  99. X
  100. X# DO NOT DELETE THIS LINE -- makedepend depends on it
  101. X
  102. Xdelete.o: /usr/include/sys/types.h /usr/include/stdio.h
  103. Xdelete.o: /usr/include/sys/stat.h /usr/include/sys/dir.h
  104. Xdelete.o: /usr/include/strings.h /usr/include/sys/param.h
  105. X# /usr/include/sys/param.h includes:
  106. X#    machine/machparam.h
  107. X#    signal.h
  108. X#    sys/types.h
  109. Xdelete.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
  110. Xdelete.o: /usr/include/sys/file.h util.h
  111. X# util.h includes:
  112. X#    mit-copyright.h
  113. Xdelete.o: mit-copyright.h delete.h
  114. X# delete.h includes:
  115. X#    mit-copyright.h
  116. Xundelete.o: /usr/include/stdio.h /usr/include/sys/types.h
  117. Xundelete.o: /usr/include/sys/dir.h /usr/include/sys/param.h
  118. Xundelete.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
  119. Xundelete.o: /usr/include/strings.h /usr/include/sys/stat.h directories.h
  120. X# directories.h includes:
  121. X#    mit-copyright.h
  122. Xundelete.o: mit-copyright.h pattern.h
  123. X# pattern.h includes:
  124. X#    mit-copyright.h
  125. Xundelete.o: util.h undelete.h
  126. X# undelete.h includes:
  127. X#    mit-copyright.h
  128. Xdirectories.o: /usr/include/sys/types.h /usr/include/sys/stat.h
  129. Xdirectories.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
  130. Xdirectories.o: /usr/include/sys/signal.h /usr/include/sys/dir.h
  131. Xdirectories.o: /usr/include/strings.h directories.h mit-copyright.h util.h
  132. Xpattern.o: /usr/include/stdio.h /usr/include/sys/types.h
  133. Xpattern.o: /usr/include/sys/dir.h /usr/include/sys/param.h
  134. Xpattern.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
  135. Xpattern.o: /usr/include/strings.h /usr/include/sys/stat.h directories.h
  136. Xpattern.o: mit-copyright.h pattern.h util.h undelete.h
  137. Xutil.o: /usr/include/stdio.h /usr/include/sys/param.h
  138. Xutil.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
  139. Xutil.o: /usr/include/sys/types.h /usr/include/sys/stat.h
  140. Xutil.o: /usr/include/sys/dir.h /usr/include/strings.h /usr/include/pwd.h
  141. Xutil.o: directories.h mit-copyright.h util.h
  142. Xexpunge.o: /usr/include/stdio.h /usr/include/sys/types.h
  143. Xexpunge.o: /usr/include/sys/time.h
  144. X# /usr/include/sys/time.h includes:
  145. X#    time.h
  146. Xexpunge.o: /usr/include/sys/time.h /usr/include/sys/dir.h
  147. Xexpunge.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
  148. Xexpunge.o: /usr/include/sys/signal.h /usr/include/strings.h
  149. Xexpunge.o: /usr/include/sys/stat.h col.h
  150. X# col.h includes:
  151. X#    mit-copyright.h
  152. Xexpunge.o: mit-copyright.h directories.h util.h pattern.h expunge.h
  153. X# expunge.h includes:
  154. X#    mit-copyright.h
  155. Xlsdel.o: /usr/include/stdio.h /usr/include/sys/types.h /usr/include/sys/dir.h
  156. Xlsdel.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
  157. Xlsdel.o: /usr/include/sys/signal.h /usr/include/sys/stat.h
  158. Xlsdel.o: /usr/include/strings.h col.h mit-copyright.h util.h directories.h
  159. Xlsdel.o: pattern.h lsdel.h
  160. X# lsdel.h includes:
  161. X#    mit-copyright.h
  162. Xcol.o: /usr/include/stdio.h /usr/include/strings.h col.h mit-copyright.h
  163. END_OF_FILE
  164. if test 4426 -ne `wc -c <'Makefile'`; then
  165.     echo shar: \"'Makefile'\" unpacked with wrong size!
  166. fi
  167. # end of 'Makefile'
  168. fi
  169. if test -f 'col.c' -a "${1}" != "-c" ; then 
  170.   echo shar: Will not clobber existing file \"'col.c'\"
  171. else
  172. echo shar: Extracting \"'col.c'\" \(5298 characters\)
  173. sed "s/^X//" >'col.c' <<'END_OF_FILE'
  174. X/*
  175. X * $Source: /mit/jik/src/delete/RCS/col.c,v $
  176. X * $Author: jik $
  177. X *
  178. X * This program is part of a package including delete, undelete,
  179. X * lsdel, expunge and purge.  The software suite is meant as a
  180. X * replacement for rm which allows for file recovery.
  181. X * 
  182. X * Copyright (c) 1989 by the Massachusetts Institute of Technology.
  183. X * For copying and distribution information, see the file "mit-copyright.h."
  184. X */
  185. X
  186. X#if (!defined(lint) && !defined(SABER))
  187. X     static char rcsid_col_c[] = "$Header: col.c,v 1.2 89/03/27 12:05:12 jik Exp $";
  188. X#endif
  189. X
  190. X/*
  191. X * Note that this function has a lot of options I'm not really using
  192. X * because I took it out of other code that needed a lot more
  193. X * versatility.
  194. X */
  195. X
  196. X#include <stdio.h>
  197. X#include <strings.h>
  198. X#include "col.h"
  199. X#include "mit-copyright.h"
  200. X
  201. X
  202. Xstatic int calc_string_width();
  203. Xstatic void trim_strings();
  204. Xextern char *malloc();
  205. Xextern char *whoami;
  206. X
  207. Xint column_array(strings, num_to_print, screen_width, column_width,
  208. X         number_of_columns, margin, spread_flag, 
  209. X         number_flag, var_col_flag, outfile)
  210. Xchar **strings;
  211. XFILE *outfile;
  212. X{
  213. X     char buf[BUFSIZ];
  214. X     int updown, leftright, height;
  215. X     int string_width;
  216. X     int numwidth;
  217. X     
  218. X
  219. X     numwidth = num_width(num_to_print);
  220. X     if (! var_col_flag) {
  221. X      string_width = calc_string_width(column_width, margin, number_flag,
  222. X                       num_to_print);
  223. X      if (string_width < 0) {
  224. X           fprintf(stderr,
  225. X               "%s: do_wait: your columns aren't wide enough!\n",
  226. X               whoami);
  227. X           return(1);
  228. X      }
  229. X      trim_strings(strings, num_to_print, string_width);
  230. X     } else if (calc_widths(strings, &screen_width, &column_width,
  231. X                &number_of_columns, num_to_print, &margin,
  232. X                spread_flag, number_flag))
  233. X      return(1);
  234. X
  235. X     height = num_to_print / number_of_columns;
  236. X     if (num_to_print % number_of_columns)
  237. X      height++;
  238. X     
  239. X     if (number_flag) for (updown = 0; updown < height; updown++) {
  240. X      for (leftright = updown; leftright < num_to_print;
  241. X           leftright += height) {
  242. X           (void) sprintf(buf, "%*d. %s", numwidth, leftright+1,
  243. X                  strings[leftright]);
  244. X           fprintf(outfile, "%*s", -column_width, buf);
  245. X      }
  246. X      fprintf(outfile, "\n");
  247. X     } else for (updown = 0; updown < height; updown++) {
  248. X      for (leftright = updown; leftright < num_to_print;
  249. X           leftright += height) {
  250. X           (void) sprintf(buf, "%s", strings[leftright]);
  251. X           fprintf(outfile, "%*s", -column_width, buf);
  252. X      }
  253. X      fprintf(outfile, "\n");
  254. X     }
  255. X     
  256. X     return(0);
  257. X}
  258. X
  259. Xstatic int calc_string_width(column_width, margin, number_flag, max_number)
  260. X{
  261. X     int string_width;
  262. X     
  263. X     string_width = column_width - margin;
  264. X     if (number_flag)
  265. X      string_width = string_width - num_width(max_number) - strlen(". ");
  266. X     return(string_width);
  267. X}
  268. X
  269. X
  270. Xstatic void trim_strings(strings, number, width)
  271. Xchar **strings;
  272. X{
  273. X     int loop;
  274. X     
  275. X     for (loop = 0; loop < number; loop++)
  276. X      if (strlen(strings[loop]) > width)
  277. X           strings[loop][width] = '\0';
  278. X}
  279. X
  280. X
  281. Xstatic int calc_widths(strings, screen_width, column_width, number_of_columns,
  282. X               num_to_print, margin, spread_flag, number_flag)
  283. Xint *screen_width, *column_width, *number_of_columns, *margin;
  284. Xchar **strings;
  285. X{
  286. X     int loop;
  287. X     int maxlen, templen;
  288. X     int spread;
  289. X     
  290. X#ifdef DEBUG
  291. X     printf("calc_widths starting with screen_width %d column_width %d number_of_columns %d margin %d num_to_print %d spread_flag %d number_flag %d\n", *screen_width, *column_width, *number_of_columns, *margin, num_to_print, spread_flag, number_flag);
  292. X#endif
  293. X     maxlen = templen = 0;
  294. X     for (loop = 0; loop < num_to_print; loop++)
  295. X      if (maxlen < (templen = strlen(strings[loop])))
  296. X           maxlen = templen;
  297. X#ifdef DEBUG
  298. X     printf("calc_widths maxlen %d\n", maxlen);
  299. X#endif
  300. X     *column_width = maxlen;
  301. X     
  302. X     if (number_flag)
  303. X      *column_width = *column_width + num_width(num_to_print) +
  304. X           strlen(". ");
  305. X
  306. X     if (! spread_flag) {
  307. X      *column_width += *margin;
  308. X      if (! *number_of_columns) {
  309. X           *number_of_columns = *screen_width / *column_width;
  310. X           if (! *number_of_columns) {
  311. X            (*number_of_columns)++;
  312. X            *column_width -= *margin;
  313. X            *margin = 0;
  314. X            *screen_width = *column_width;
  315. X           }
  316. X      }
  317. X      else
  318. X           *screen_width = *number_of_columns * *column_width;
  319. X     } else {
  320. X      if (! *number_of_columns) {
  321. X           *number_of_columns = *screen_width / (*column_width + *margin);
  322. X           if (! *number_of_columns) {
  323. X            (*number_of_columns)++;
  324. X            *screen_width = *column_width;
  325. X            *margin = 0;
  326. X           }
  327. X           spread = (*screen_width - *number_of_columns * *column_width)
  328. X            / *number_of_columns;
  329. X           *column_width += spread;
  330. X      }
  331. X      else {
  332. X           if (*number_of_columns * (*column_width + *margin) >
  333. X           *screen_width) {
  334. X            *column_width += *margin;
  335. X            *screen_width = *column_width;
  336. X           } else {
  337. X            spread = (*screen_width - (*number_of_columns *
  338. X                           *column_width)) /
  339. X                            *number_of_columns;
  340. X            *column_width += spread;
  341. X           }
  342. X      }
  343. X     }
  344. X#ifdef DEBUG
  345. X     printf("calc_widths returning screen_width %d column_width %d number_of_columns %d margin %d\n", *screen_width, *column_width, *number_of_columns, *margin);
  346. X#endif
  347. X     return(0);
  348. X}
  349. X
  350. X
  351. X           
  352. X
  353. Xstatic int num_width(number)
  354. X{
  355. X     char buf[BUFSIZ];
  356. X
  357. X     return(strlen(sprintf(buf, "%d", number)));
  358. X}
  359. END_OF_FILE
  360. if test 5298 -ne `wc -c <'col.c'`; then
  361.     echo shar: \"'col.c'\" unpacked with wrong size!
  362. fi
  363. # end of 'col.c'
  364. fi
  365. if test -f 'man1/delete.1' -a "${1}" != "-c" ; then 
  366.   echo shar: Will not clobber existing file \"'man1/delete.1'\"
  367. else
  368. echo shar: Extracting \"'man1/delete.1'\" \(3945 characters\)
  369. sed "s/^X//" >'man1/delete.1' <<'END_OF_FILE'
  370. X.\"    $Source: /mit/jik/src/delete/man1/RCS/delete.1,v $
  371. X.\"    $Author: jik $
  372. X.\"    $Header: delete.1,v 1.4 89/03/27 11:32:54 jik Exp $
  373. X.\"
  374. X.\" Copyright 1989 by the Massachusetts Institute of Technology.  All
  375. X.\" rights reserved.  The file /usr/include/mit-copyright.h specifies
  376. X.\" the terms and conditions for redistribution.
  377. X.\"
  378. X.\"
  379. X.TH DELETE 1 "January 26, 1988" "MIT Project Athena"
  380. X.ds ]W MIT Project Athena
  381. X.SH NAME
  382. Xdelete \- a recoverable file-deletion utility
  383. X.SH SYNOPSIS
  384. X.B delete
  385. X[
  386. X.B \-r
  387. X] [
  388. X.B \-i
  389. X] [
  390. X.B \-f
  391. X] [
  392. X.B \-n
  393. X] [
  394. X.B \-v
  395. X] [
  396. X.B \-F
  397. X] [
  398. X.B \-D
  399. X] [
  400. X.B \-\|\-
  401. X] filename ...
  402. X.PP
  403. X.SH DESCRIPTION
  404. X.I Delete
  405. Xmarks files and directories for later permanent removal (by renaming
  406. Xthem with a prefix of \fI.#\fR).  Files accidentally marked for deletion
  407. Xcan be recovered using
  408. X.I undelete(1).
  409. XMarked files are periodically
  410. Xremoved automatically by the system; they can also be removed on demand
  411. X(see \fIpurge\fR(1) and \fIexpunge\fR(1) for details).
  412. XUsers can list files which have been marked for
  413. Xremoval but have not yet been removed using \fIlsdel\fR(1).
  414. X.PP
  415. XIf the user does not have write permission to a file, its permissions
  416. Xare printed and the user is asked whether the file should be removed.
  417. XIf the first character of the response line is \fIy\fR the file is
  418. Xremoved, otherwise it remains.
  419. X.PP
  420. XUsers wishing to retain the user interface of \fIrm\fR(1)
  421. Xand \fIrmdir\fR(1)
  422. Xwhile still being able to recover accidentally removed files can do so
  423. Xby aliasing
  424. X.I rm
  425. Xto
  426. X.I delete \-F
  427. Xand
  428. X.I rmdir
  429. Xto
  430. X.I delete \-D
  431. X(see below).
  432. X.SH OPTIONS
  433. X.I Delete
  434. Xaccepts the following command-line options:
  435. X.TP
  436. X.B \-r
  437. XIf a designated filename is a non-empty directory,
  438. X.I delete
  439. Xwill signal an error unless the
  440. X.B \-r
  441. Xoption is specified.  In that case,
  442. X.I delete
  443. Xrecursively deletes the directory's entire contents and the directory
  444. Xitself.  If the
  445. X.B \-F
  446. Xoption is specified (see below),
  447. X.I delete
  448. Xwill signal an error even if the directory is empty.
  449. X.TP
  450. X.B \-i
  451. XCauses
  452. X.I delete
  453. Xto ask whether to delete each file, and, in recursive
  454. Xmode, whether to examine each directory.
  455. X.TP
  456. X.B \-f
  457. XPrevents
  458. X.I delete
  459. Xfrom asking any questions and from reporting any errors.
  460. X.TP
  461. X.B \-n
  462. XNo file removals are performed.  Instead,
  463. X.I delete
  464. Xprints to the standard output the files that it would remove were the
  465. X.B \-n
  466. Xoption not specified.
  467. X.TP
  468. X.B \-v
  469. XCauses
  470. X.I delete
  471. Xto report each file as it is deleted.
  472. X.TP
  473. X.B \-F
  474. XCauses
  475. X.I delete
  476. Xto emulate
  477. X.I rm
  478. Xby preventing it from removing even empty directories when the
  479. X.B \-r
  480. Xoption is not specified.
  481. X.TP
  482. X.B \-D
  483. XCauses
  484. X.I delete
  485. Xto emulate
  486. X.I rmdir
  487. Xby preventing it from removing anything but empty directories.
  488. X.TP
  489. X.B \-\|\-
  490. XTwo dashes indicate that all the arguments following it are to be treated as
  491. Xfile names, even if they start with a dash.
  492. X.SH "SEE ALSO"
  493. Xundelete(1), purge(1), expunge(1), lsdel(1), rm(1), rmdir(1)
  494. X.SH AUTHOR
  495. XJonathan I. Kamens (MIT-Project Athena)
  496. X.SH COPYRIGHT
  497. XCopyright (c) 1989 by the Massachusetts Institute of Technology.
  498. X.PP
  499. XAll rights reserved.
  500. X.PP
  501. XPermission to use, copy, modify, and distribute this software and its
  502. Xdocumentation for any purpose and without fee is hereby granted,
  503. Xprovided that the above copyright notice appear in all copies and that
  504. Xboth that copyright notice and this permission notice appear in
  505. Xsupporting documentation, and that the name of the Massachusetts
  506. XInstitute of Technology (M.I.T.) not be used in advertising or publicity
  507. Xpertaining to distribution of the software without specific, written
  508. Xprior permission.
  509. X.PP
  510. XM.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  511. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  512. XM.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  513. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  514. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  515. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  516. XSOFTWARE.
  517. X
  518. X
  519. END_OF_FILE
  520. if test 3945 -ne `wc -c <'man1/delete.1'`; then
  521.     echo shar: \"'man1/delete.1'\" unpacked with wrong size!
  522. fi
  523. # end of 'man1/delete.1'
  524. fi
  525. if test -f 'util.c' -a "${1}" != "-c" ; then 
  526.   echo shar: Will not clobber existing file \"'util.c'\"
  527. else
  528. echo shar: Extracting \"'util.c'\" \(4579 characters\)
  529. sed "s/^X//" >'util.c' <<'END_OF_FILE'
  530. X/*
  531. X * $Source: /mit/jik/src/delete/RCS/util.c,v $
  532. X * $Author: jik $
  533. X *
  534. X * This program is a replacement for rm.  Instead of actually deleting
  535. X * files, it marks them for deletion by prefixing them with a ".#"
  536. X * prefix.
  537. X *
  538. X * Copyright (c) 1989 by the Massachusetts Institute of Technology.
  539. X * For copying and distribution information, see the file "mit-copyright.h."
  540. X */
  541. X
  542. X#if (!defined(lint) && !defined(SABER))
  543. X     static char rcsid_util_c[] = "$Header: util.c,v 1.7 89/03/27 12:08:34 jik Exp $";
  544. X#endif
  545. X
  546. X#include <stdio.h>
  547. X#include <sys/param.h>
  548. X#include <sys/types.h>
  549. X#include <sys/stat.h>
  550. X#include <sys/dir.h>
  551. X#include <strings.h>
  552. X#include <pwd.h>
  553. X#include "directories.h"
  554. X#include "util.h"
  555. X#include "mit-copyright.h"
  556. X
  557. Xchar *getenv();
  558. X
  559. X
  560. Xchar *convert_to_user_name(real_name, user_name)
  561. Xchar real_name[];
  562. Xchar user_name[];  /* RETURN */
  563. X{
  564. X     char *ptr, *q;
  565. X     
  566. X     strcpy(user_name, real_name);
  567. X     while (ptr = strrindex(user_name, ".#")) {
  568. X      for (q = ptr; *(q + 2); q++)
  569. X           *q = *(q + 2);
  570. X      *q = '\0';
  571. X     }
  572. X     return (user_name);
  573. X}
  574. X
  575. X     
  576. X
  577. X
  578. X
  579. Xchar *strindex(str, sub_str)
  580. Xchar *str, *sub_str;
  581. X{
  582. X     char *ptr = str;
  583. X     while (ptr = index(ptr, *sub_str)) {
  584. X      if (! strncmp(ptr, sub_str, strlen(sub_str)))
  585. X           return(ptr);
  586. X      ptr++;
  587. X     }
  588. X     return ((char *) NULL);
  589. X}
  590. X
  591. X
  592. X
  593. Xchar *strrindex(str, sub_str)
  594. Xchar *str, *sub_str;
  595. X{
  596. X     char *ptr;
  597. X
  598. X     if (strlen(str))
  599. X      ptr = &str[strlen(str) - 1];
  600. X     else
  601. X      return((char *) NULL);
  602. X     while ((*ptr != *sub_str) && (ptr != str)) ptr--;
  603. X     while (ptr != str) {
  604. X      if (! strncmp(ptr, sub_str, strlen(sub_str)))
  605. X           return(ptr);
  606. X      ptr--;
  607. X      while ((*ptr != *sub_str) && (ptr != str)) ptr--;
  608. X     }
  609. X     if (! strncmp(ptr, sub_str, strlen(sub_str)))
  610. X      return(str);
  611. X     else
  612. X      return ((char *) NULL);
  613. X}
  614. X     
  615. X     
  616. Xis_dotfile(filename)
  617. Xchar *filename;
  618. X{
  619. X     return (! (strcmp(filename, ".") && strcmp(filename, "..")));
  620. X}
  621. X
  622. X
  623. X
  624. Xint is_deleted(filename)
  625. Xchar *filename;
  626. X{
  627. X     return(! strncmp(filename, ".#", 2));
  628. X}
  629. X
  630. X
  631. X
  632. X
  633. X/*
  634. X * NOTE: Append uses a static array, so its return value must be
  635. X * copied immediately.
  636. X */
  637. Xchar *append(filepath, filename)
  638. Xchar *filepath, *filename;
  639. X{
  640. X     static char buf[MAXPATHLEN];
  641. X
  642. X     strcpy(buf, filepath);
  643. X     if ((! *filename) || (! *filepath)) {
  644. X      strcpy(buf, filename);
  645. X      return(buf);
  646. X     }
  647. X     if (buf[strlen(buf) - 1] == '/')
  648. X      buf[strlen(buf) - 1] = '\0';
  649. X     if (strlen(buf) + strlen(filename) + 2 > MAXPATHLEN) {
  650. X       *buf = '\0';
  651. X      return(buf);
  652. X     }
  653. X     strcat(buf, "/");
  654. X     strcat(buf, filename);
  655. X     return(buf);
  656. X}
  657. X
  658. X
  659. X
  660. X
  661. Xyes() {
  662. X     char buf[BUFSIZ];
  663. X     char *val;
  664. X     
  665. X     val = fgets(buf, BUFSIZ, stdin);
  666. X     if (! val) {
  667. X      printf("\n");
  668. X      exit(1);
  669. X     }
  670. X     if (! index(buf, '\n')) do
  671. X      fgets(buf + 1, BUFSIZ - 1, stdin);
  672. X     while (! index(buf + 1, '\n'));
  673. X     return(*buf == 'y');
  674. X}
  675. X
  676. X
  677. X
  678. X
  679. Xchar *lastpart(filename)
  680. Xchar *filename;
  681. X{
  682. X     char *part;
  683. X
  684. X     part = rindex(filename, '/');
  685. X
  686. X     if (! part)
  687. X      part = filename;
  688. X     else if (part == filename)
  689. X      part++;
  690. X     else if (part - filename + 1 == strlen(filename)) {
  691. X      part = rindex(--part, '/');
  692. X      if (! part)
  693. X           part = filename;
  694. X      else
  695. X           part++;
  696. X     }
  697. X     else
  698. X      part++;
  699. X
  700. X     return(part);
  701. X}
  702. X
  703. X
  704. X
  705. X
  706. Xchar *firstpart(filename, rest)
  707. Xchar *filename;
  708. Xchar *rest; /* RETURN */
  709. X{
  710. X     char *part;
  711. X     static char buf[MAXPATHLEN];
  712. X
  713. X     strcpy(buf, filename);
  714. X     part = index(buf, '/');
  715. X     if (! part) {
  716. X      *rest = '\0';
  717. X      return(buf);
  718. X     }
  719. X     strcpy(rest, part + 1);
  720. X     *part = '\0';
  721. X     return(buf);
  722. X}
  723. X
  724. X
  725. X
  726. X
  727. Xchar *reg_firstpart(filename, rest)
  728. Xchar *filename;
  729. Xchar *rest; /* RETURN */
  730. X{
  731. X     static char first[MAXNAMLEN];
  732. X     
  733. X     sprintf(first, "^%s$", firstpart(filename, rest));
  734. X     return(first);
  735. X}
  736. X
  737. X
  738. X
  739. X
  740. X
  741. X
  742. Xget_home(buf)
  743. Xchar *buf;
  744. X{
  745. X     char *user;
  746. X     struct passwd *psw;
  747. X     
  748. X     strcpy(buf, getenv("HOME"));
  749. X     
  750. X     if (*buf)
  751. X      return(0);
  752. X
  753. X     user = getenv("USER");
  754. X     psw = getpwnam(user);
  755. X
  756. X     if (psw) {
  757. X      strcpy(buf, psw->pw_dir);
  758. X      return(0);
  759. X     }
  760. X     
  761. X     psw = getpwuid(getuid());
  762. X
  763. X     if (psw) {
  764. X      strcpy(buf, psw->pw_dir);
  765. X      return(0);
  766. X     }  
  767. X     return(1);
  768. X}
  769. X
  770. X
  771. X
  772. X
  773. Xtimed_out(file_ent, current_time, min_days)
  774. Xfilerec *file_ent;
  775. Xint current_time, min_days;
  776. X{
  777. X     if ((current_time - file_ent->specs.st_mtime) / 86400 >= min_days)
  778. X      return(1);
  779. X     else
  780. X      return(0);
  781. X}
  782. X
  783. X
  784. X
  785. Xint directory_exists(dirname)
  786. Xchar *dirname;
  787. X{
  788. X     struct stat stat_buf;
  789. X
  790. X     if (stat(dirname, &stat_buf))
  791. X      return(0);
  792. X     else if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
  793. X      return(1);
  794. X     else
  795. X      return(0);
  796. X}
  797. X
  798. X           
  799. END_OF_FILE
  800. if test 4579 -ne `wc -c <'util.c'`; then
  801.     echo shar: \"'util.c'\" unpacked with wrong size!
  802. fi
  803. # end of 'util.c'
  804. fi
  805. echo shar: End of archive 2 \(of 6\).
  806. cp /dev/null ark2isdone
  807. MISSING=""
  808. for I in 1 2 3 4 5 6 ; do
  809.     if test ! -f ark${I}isdone ; then
  810.     MISSING="${MISSING} ${I}"
  811.     fi
  812. done
  813. if test "${MISSING}" = "" ; then
  814.     echo You have unpacked all 6 archives.
  815.     rm -f ark[1-9]isdone
  816. else
  817.     echo You still need to unpack the following archives:
  818.     echo "        " ${MISSING}
  819. fi
  820. ##  End of shell archive.
  821. exit 0
  822.  
  823. -- 
  824. Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
  825.  
  826.  
  827.